package com.gangquan360.smartadmin.module.product.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.gangquan360.smartadmin.common.domain.PageResultDTO;
import com.gangquan360.smartadmin.common.domain.ResponseDTO;
import com.gangquan360.smartadmin.module.product.dao.ProductTagDao;
import com.gangquan360.smartadmin.module.product.domain.dto.ProductTagDTO;
import com.gangquan360.smartadmin.module.product.domain.dto.ProductTagQueryDTO;
import com.gangquan360.smartadmin.module.product.domain.entity.ProductTagEntity;
import com.gangquan360.smartadmin.util.SmartBeanUtil;
import com.gangquan360.smartadmin.util.SmartPaginationUtil;

/**
 * [ 产品标签表 ]
 *
 * @author wiggin
 * @version 1.0
 * @company wiggin
 * @copyright (c) 2019 wigginInc. All rights reserved.
 * @date 2020-03-14 21:33:16
 * @since JDK1.8
 */
@Service
public class ProductTagService {

    @Autowired
    private ProductTagDao productTagDao;


    /**
     * @author wiggin
     * @description 分页查询
     * @date 2020-03-14 21:33:16
     */
    public ResponseDTO<PageResultDTO<ProductTagDTO>> queryByPage(ProductTagQueryDTO queryDTO) {
        Page<ProductTagDTO> page = SmartPaginationUtil.convert2PageQueryInfo(queryDTO);
        List<ProductTagEntity> entities = productTagDao.queryByPage(page, queryDTO);
        List<ProductTagDTO> dtoList = SmartBeanUtil.copyList(entities, ProductTagDTO.class);
        page.setRecords(dtoList);
        PageResultDTO<ProductTagDTO> pageResultDTO = SmartPaginationUtil.convert2PageResultDTO(page);
        return ResponseDTO.succData(pageResultDTO);
    }
    
    
    /**
     * 
     * @return
     */
    public ResponseDTO<List<ProductTagDTO>> queryList() {
    	Wrapper<ProductTagEntity> wrapper = new EntityWrapper<>();
		List<ProductTagEntity> selectList = productTagDao.selectList(wrapper);
		List<ProductTagDTO> copyList = SmartBeanUtil.copyList(selectList, ProductTagDTO.class);
		return ResponseDTO.succData(copyList);
    }

    /**
     * @author wiggin
     * @description 添加
     * @date 2020-03-14 21:33:16
     */
    public ResponseDTO<String> add(ProductTagDTO addDTO) {
        ProductTagEntity entity = SmartBeanUtil.copy(addDTO, ProductTagEntity.class);
        productTagDao.insert(entity);
        return ResponseDTO.succ();
    }


    /**
     * @author wiggin
     * @description 编辑
     * @date 2020-03-14 21:33:16
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(ProductTagDTO updateDTO) {
        ProductTagEntity entity = SmartBeanUtil.copy(updateDTO, ProductTagEntity.class);
        productTagDao.updateById(entity);
        return ResponseDTO.succ();
    }


    /**
     * @author wiggin
     * @description 删除
     * @date 2020-03-14 21:33:16
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> delete(Long id) {
        productTagDao.deleteById(id);
        return ResponseDTO.succ();
    }

    /**
     * @author wiggin
     * @description  根据ID查询
     * @date 2020-03-14 21:33:16
    */
    public ResponseDTO<ProductTagDTO> detail(Long id){
        ProductTagEntity entity = productTagDao.selectById(id);
        ProductTagDTO dto =  SmartBeanUtil.copy(entity,ProductTagDTO.class);
        return ResponseDTO.succData(dto);
    }
}
